//
//  GGView.swift
//  SwitfTest
//
//  Created by runone02 on 2019/1/23.
//  Copyright © 2019年 liqiyun. All rights reserved.
//

import UIKit

class GGView: UIView {
    private var XButton : UIButton!
    private var titleLabel : UILabel!
    //初始化
    override init(frame: CGRect) {
        super.init(frame: frame)
        //设置背景为灰色
        self.backgroundColor = UIColor.orange
    }
    //自动布局
    override func layoutSubviews() {
        titleLabel = UILabel()
        titleLabel.text = "广告跳转界面"
        titleLabel.textColor = UIColor.black
        titleLabel.font = UIFont.systemFont(ofSize: 15)
        self.addSubview(titleLabel)
        titleLabel.mas_makeConstraints { (make) in
            make?.top.mas_equalTo()(kStatusBarHeight)
            make?.centerX.mas_equalTo()(self)
            make?.height.mas_equalTo()(30)
        }
        
        XButton = UIButton(type: .custom)
        XButton.layer.masksToBounds = true
        XButton.layer.borderWidth = 1
        XButton.layer.borderColor = UIColor.black.cgColor
        XButton.layer.cornerRadius = 25
        XButton.setTitle("X", for: .normal)
        XButton.setTitleColor(UIColor.black, for: .normal)
        XButton.backgroundColor = UIColor.white
        XButton.addTarget(self, action: #selector(XButtonClick(button:)), for: .touchUpInside)
        self.addSubview(XButton)
        XButton.mas_makeConstraints { (make) in
            make?.bottom.mas_equalTo()(self)?.offset()(-15)
            make?.centerX.mas_equalTo()(self)
            make?.width.mas_equalTo()(50)
            make?.height.mas_equalTo()(50)
        }
        
    }
    
    ///移除
    @objc private func XButtonClick(button:UIButton){
        self.removeFromSuperview()
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }


}
